package tuilayer;
import java.util.*;

public class MainMenuUI {
    private PersonUI personUI;
    private LoanUI loanUI;
    private DVDUI dvdUI;
    
    public MainMenuUI(){
        personUI = new PersonUI();
        loanUI = new LoanUI();
        dvdUI = new DVDUI();
        start();
    }
    
    private void start() {
        mainMenu();
    }

    private void mainMenu() {
        boolean stop = false;
        while (!stop) {
            int choice = writeMainMenu();
            switch (choice) {
                case 0:
                    stop = true;
                    break;
                case 1:
                    personUI.handlePerson();
                    break;
                case 2:
                    loanUI.handleLoan();
                    break;
                case 3:
                    dvdUI.handleDVD();
                    break;
                default: System.out.println("Please enter a valid choice.");
            }
        }
        System.out.println("\nGoodbye!");
    }
    
    private int writeMainMenu() {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\n*****Main Menu*****");
        System.out.println("(0) Exit");
        System.out.println("(1) Person");
        System.out.println("(2) Loan");
        System.out.println("(3) DVD");
        System.out.println("\nRemember: you can always stop an action by pressing 0");
        System.out.println("\nType your choice:");
        
        int choice = ValidateInput.readInt("Please enter a valid choice.");
        
        if(ValidateInput.validateInt(choice))        
            return choice;
        else {
            return 999;
        } 
    }
}
